package icasue.net.socket.utils;

import icasue.net.socket.exception.PredicateException;

import java.util.Objects;

/**
 * @Author: Qiao Hang
 * @CreateDate: 2021/5/18 下午5:18
 * @UpdateDate:
 * @Description:
 */
public class Assert {

    private static final String FAIL_DEFAULT_TEMPLATE = "Assert.%s :: processor params predicate error.";

    public static void notNullAll(Object... inParams){
        if(inParams == null || inParams.length == 0)
            throw new PredicateException(String.format(FAIL_DEFAULT_TEMPLATE,"notNullAll"));
        for (Object inParam : inParams) {
            if(inParams == null){
                throw new PredicateException(String.format(FAIL_DEFAULT_TEMPLATE,"notNullAll"));
            }
        }
    }

    public static void notNull(Object inParam){
        if(inParam == null)
            throw new PredicateException(String.format(FAIL_DEFAULT_TEMPLATE,"notNull"));
    }

    public static void notNull(Object inParam,String mes){
        if(inParam == null)
            throw new PredicateException(mes == null ? mes : String.format(FAIL_DEFAULT_TEMPLATE,"notNull"));
    }

    public static void equals(Object left,Object right){
        if(!Objects.equals(left,right))
            throw new PredicateException(String.format(FAIL_DEFAULT_TEMPLATE,"equals"));
    }


}
